var d1 = require('deviceone')
var baiduLocation = d1.sm("do_BaiduLocation");
var baiduNavigate  = d1.sm("do_BaiduNavigate")
var log = require('util/log')
/**
 * 获取定位信息
 */
module.exports.getLocation = function(callback, scope) {
	// 接收到定位/更新定位时候触发
	baiduLocation.on("result", function(data, e) {
		callback.call(scope, data)
	})
	baiduLocation.start({
		model : "high",
		isLoop : false
	});
}

/**
 * 获取定位信息
 */
module.exports.navigate = function(targetPoint) {
	module.exports.getLocation(function(startPoint){
		// 接收到定位/更新定位时候触发
		var start = startPoint.latitude+','+startPoint.longitude
		var end = targetPoint.latitude+','+targetPoint.longitude
		log.info(start,end)
		baiduNavigate.on('begin',function(a,b,c,d){
			log.info('begin',a,b,c,d)
		})
		
		baiduNavigate.on('failed',function(a,b,c,d){
			log.info('failed',a,b,c,d)
		})
		
		baiduNavigate.on('success',function(a,b,c,d){
			log.info('success',a,b,c,d)
		})
		
		baiduNavigate.start({
			startPoint:start,
			endPoint:end,
			coType:'BD09LL'
			})
		})
}